package com.hsdev.caprace;

import org.andengine.engine.Engine;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.adt.color.Color;

import android.content.Context;
import android.graphics.Typeface;

public class ResourceManager {
	
	private static ResourceManager INSTANCE;
	
	public BitmapTextureAtlas splashTA;
	public ITextureRegion splashTR;
	public ITextureRegion mBackGroundRegion;
	public ITextureRegion mBialyKapselRegion;
	public ITextureRegion mCzarnyKapselRegion;
	public ITextureRegion mArrowregion;
	public ITextureRegion mBialyWygral;
	public ITextureRegion mCzarnyWygral;
	private BitmapTextureAtlas mFontAtlas;
	public Font mFont;
	
	
	private ResourceManager() {
		// TODO Auto-generated constructor stub
	}
	
	public static ResourceManager getInstance(){
		if(INSTANCE == null){
			INSTANCE = new ResourceManager();
		}
		return INSTANCE;
		
	}
	
	
	public synchronized void loadGameTextures (Engine pEngine, Context pContext){
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		
		BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(pEngine.getTextureManager(), 1024, 1024);
		
		BitmapTextureAtlas mBackgroundTextureAtlas = new BitmapTextureAtlas(pEngine.getTextureManager(), 1024, 1024);
		
		mBialyKapselRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, pContext, "kapselbialy.png", 10, 10);
		
		mCzarnyKapselRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, pContext, "kapselczarny.png", 200, 10);
		
		mArrowregion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, pContext, "Arrow.png", 400, 10);
				
		mBackGroundRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBackgroundTextureAtlas, pContext, "trasa2.png", 0, 0); 
		
		mBialyWygral = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, pContext, "bialywygral.png", 10, 300);
		
		mCzarnyWygral = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBitmapTextureAtlas, pContext, "czarnywygral.png", 10, 450);
		
		
		mBitmapTextureAtlas.load();
		mBackgroundTextureAtlas.load();
		
		
		
		
	}
	
	public synchronized void loadSplashTextures(Engine pEngine, Context pContext){
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		splashTA = new BitmapTextureAtlas(pEngine.getTextureManager(), 1024, 512);
		splashTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(splashTA, pContext, "splash.png", 10, 10);
		splashTA.load();
	}
	
	public synchronized void loadL1Fonts(Engine pEngine){
		mFontAtlas = new BitmapTextureAtlas(pEngine.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mFont = new Font(pEngine.getFontManager(), mFontAtlas, Typeface.DEFAULT, 24, true, Color.RED);
		pEngine.getTextureManager().loadTexture(this.mFontAtlas);
		pEngine.getFontManager().loadFont(this.mFont);
	}
	
	
	
	
	

}
